package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Category;
import com.itheima.reggie.service.CategoryService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
public class CategoryController {
    // 查询所有分类
    @Autowired
    private CategoryService categoryService;
    @GetMapping("/category/findAll")
    public ResultInfo findAll(){
        //调用service方法
        List<Category> list = categoryService.findAll();
        //返回查询所有信息
        return ResultInfo.success(list);

    }
    //新增菜品类
    @PostMapping("/category")
    public ResultInfo save(@RequestBody Category category){
        //调用service方法
        categoryService.save(category);
        //返回添加成功结果
        return ResultInfo.success();

    }
    //修改数据
    @PutMapping("/category")
    public ResultInfo update(@RequestBody Category category){//接收参数
        //调用service
        categoryService.updateById(category);
        //返回结果
       return ResultInfo.success();
    }
    @DeleteMapping("/category")
    public ResultInfo deleteById(Long id){
    //调用service
         categoryService.deleteById(id);
         return ResultInfo.success();
    }
    // 新增菜品/套餐时查询的分类信息
    @GetMapping("/category/list")
    public ResultInfo save(Integer type){//接收参数
        // 2.根据type查询分类
    List<Category> list=categoryService.findByType(type);
    //返回结果
        return ResultInfo.success(list);

    }
}
